// const baseURL = 'http://localhost:3030/v1';
const baseURL = 'https://volunteer.onecube.top/v1';

const request = {
  get: (url, data = {}, header = {}) => {
    return main(url, data, header, 'GET');
  }, 
  post: (url, data = {}, header = {}) => {
    return main(url, data, header, 'POST');
  }, 
  put: (url, data = {}, header = {}) => {
    return main(url, data, header, 'PUT');
  }, 
  delete: (url, data = {}, header = {}) => {
    return main(url, data, header, 'DELETE');
  }
}

function main(url, data, header, method = 'GET'){
  return new Promise((resolve,reject)=>{
    wx.request({
      url: baseURL + url,
      data,
      header,
      method,
      success: res => {
        resolve(res.data);
      },
      fail: err => {
        reject(err);
      }
    })
  })
}

module.exports = request;